home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / dialip10.zip / KILLBN.CMD < prev    next >
OS/2 REXX Batch file  |  1996-11-17  |  1KB  |  47 lines

  1. /* program: killbyname  (a freeby)
  2. ** written: Stan J. Towianski
  3. ** purpose: killbyname arg, will kill the 1st process that matches the
  4. **          name given in arg.
  5. **    date: 1995
  6. **    note: needs to have kill.exe program in path.
  7. **          This can be found in c:\grpware\clients from OS/2 Warp 3.0
  8. **          Also uses hardcoded filename of c:\out which can be 
  9. **          changed.
  10. */
  11.  
  12. parse upper arg options searchname num_to_kill
  13. tmp = value( 'TMP', , 'OS2ENVIRONMENT' )
  14. listfile = tmp'\killbn.tmp'
  15. 'pstat /c > 'listfile
  16.  
  17. just_find_flag = 'N'
  18. decpid = -1
  19. if ( left( options, 1 ) \= '-' ) then
  20.     Do
  21.     num_to_kill = searchname
  22.     searchname = options
  23.     End
  24. else if ( pos( '-F', options ) > 0 ) then
  25.     just_find_flag = 'Y'
  26.  
  27. Do While( lines( listfile ) )
  28.     word = linein( listfile )
  29.     parse var word pid . . procname rest
  30.     say "pid ="pid     "procname ="procname"="
  31.     if ( pos( searchname, procname ) > 0 ) then
  32.         Do
  33.         decpid = x2d( pid )
  34.         if ( just_find_flag = 'Y' ) then
  35.             Do
  36.             say 'found name with hex pid = 'pid   'decpid = 'decpid
  37.             leave
  38.             End
  39.         "kill "decpid
  40.         leave
  41.         End
  42. End
  43. rc = stream( listfile, 'c', "close" )
  44. "del "listfile
  45. return decpid
  46.  
  47.